/*
 * Copyright (c) 2015, Tido Klaassen. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. No personal names or organizations' names associated with the
 *    Atomthreads project may be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */


#include "atom.h"
#include "iosdrv.h"
#include "debug.h"
#include "drv_common.h"
#include "drv_console.h"
#include "drv_rtc.h"
#include "drv_pin.h"
#include "drv_uart.h"
#include "drv_spi.h"
#include "drv_adc.h"
#include "drv_pwm.h"
#include "simI2c.h"
#include "device.h"
#include "drv_i2c.h"

/**
 * Callback from your main program to set up the board's hardware before
 * the kernel is started.
 */
int board_setup(void)
{
    DrvCommonInit();

    DeviceInit();

#ifdef COM_USE_DBGPORT    
    static UpConsole _upConsole;
    UpConsoleCreate(&_upConsole, "console");
#endif    

#ifdef BSP_USE_RTC
    static UpboardRtc _rtc;
    UpRtcCreate(&_rtc);
#endif

#ifdef BSP_USE_PIN
    UpPinCreate();
#endif

#ifdef BSP_USE_UART
    static UpboardUart _uart;
    static SIO_PARAM _default = { 115200, 8, ssb1Bit,  spNone, FALSE, FALSE, enSioBlockingSend };
    UpUartCreate(&_uart, "uart", &_default);
#endif

#ifdef BSP_USE_SPI
    static UpboardSpi _spi;
    UpSpiCreate(&_spi, "spi", 1000000, SPI_LSB_FIRST, 16, 0, 0, 16);
#endif

#ifdef BSP_USE_ADC
    static UpboardAdc _adc;
    UpAdcCreate(&_adc, "adc0");
#endif

#ifdef BSP_USE_PWM
    static UpboardPwm _pwm;
    UpPwmCreate(&_pwm);
#endif

    static SimI2cConfig config = { 29, 31, "simiic" };
    SimI2cCreate(&config, 1);

 #ifdef DEVICE_USE_GNSS
    //DeviceUnicoreGnssCreate();
#endif

#ifdef BSP_USE_IIC
    UpboardI2cCreate();
#endif

    return 0;
}
